package leetcode_5000;

import java.util.ArrayList;
import java.util.List;

public class _有效子数组的数目 {
	public static void main(String[] args) {
		_有效子数组的数目 test = new _有效子数组的数目();
		System.out.println(test.validSubarrays(new int[] {2,2,2}));
		System.out.println(test.validSubarrays(new int[] {3,2,1}));
		System.out.println(test.validSubarrays(new int[] {1,4,2,5,3}));
	}
	
	public int validSubarrays(int[] nums) {
		int res = 1;
        List<Integer> list = new ArrayList<Integer>();
        list.add(nums[0]);
        for(int i=1;i<nums.length;++i) {
        	res++;
        	List<Integer> nlist = new ArrayList<Integer>();
        	for(Integer now:list) {
        		if(now<=nums[i]) {
        			++res;
        			nlist.add(now);
        		}
        	}
        	nlist.add(nums[i]);
        	list = nlist;
        }
        return res;
    }
}
